package utils;

import application.App;

/**
 *
 * Created by meixin.song on 2018/4/10.
 */

public class Session {
    private static String channel = "";
    private static String cookie = "";
    private static String deviceToken = ""; //友盟推送设备唯一标识符

    private static String uid = ""; //uid

    private static boolean isFirstOpen = true;//是否第一次打开应用


    public static String getUid() {

        if (VerifyUtil.isEmpty(uid)) {
            uid = SPUtils.getInstance(App.getInstance()).getString("uid", "");
        }
        return uid;
    }

    public static void setUid(String uid) {
        Session.uid = uid;
        SPUtils.getInstance(App.getInstance()).put("uid", VerifyUtil.isEmpty(uid) ? "" : uid);
    }

    public static boolean isFirstOpen() {
        isFirstOpen = SPUtils.getInstance(App.getInstance()).getBoolean("isFirstOpen", false);
        return isFirstOpen;
    }

    public static void setIsFirstOpen(boolean isFirstOpen) {
        Session.isFirstOpen = isFirstOpen;
        SPUtils.getInstance(App.getInstance()).put("isFirstOpen", isFirstOpen);
    }

    public static String getCookie() {
        if (VerifyUtil.isEmpty(cookie)) {
            cookie = SPUtils.getInstance(App.getInstance()).getString("cookie", "");
        }
        return cookie;
    }

    public static void setCookie(String cookie) {
        Session.cookie = cookie;
        SPUtils.getInstance(App.getInstance()).put("cookie", VerifyUtil.isEmpty(cookie) ? "" : cookie);
    }

    public static String getDeviceToken() {
        if (VerifyUtil.isEmpty(deviceToken)) {
            deviceToken = SPUtils.getInstance(App.getInstance()).getString("deviceToken", "");
        }
        return deviceToken;
    }

    public static void setDeviceToken(String deviceToken) {
        Session.deviceToken = deviceToken;
        SPUtils.getInstance(App.getInstance()).put("deviceToken", VerifyUtil.isEmpty(deviceToken) ? "" : deviceToken);
    }

    public static void logout(){
        Session.setCookie("");
        Session.setUid("");
    }




}
